#include<stdio.h>
#include<queue>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<memory>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<malloc.h>
#include<iostream>
using namespace std;
#define exp(x) (1<<x)
#define N 8
#define M 6561
int base[N], tag[M][exp(N)], cnt[M], one[exp(N)];
int g[3][3], flag[3][3];
int diret[][2] =
{
{ 1, 0 },
{ -1, 0 },
{ 0, 1 },
{ 0, -1 } };
void dfs(int x, int y)
{
	flag[x][y] = 1;
	int next_x, next_y;
	if (g[x][y] == 0)
	{
		for (int i = 0; i < 4; i++)
		{
			next_x = x + diret[i][0];
			next_y = y + diret[i][1];
			if (next_x >= 0 && next_x < 3 && next_y >= 0 && next_y < 3
					&& flag[next_x][next_y] == 0)
				dfs(next_x, next_y);
		}
	}
}
void get_g(int x)
{
	int i, j, k;
	for (i = 0; i < 3; i++)
		for (j = 0; j < 3; j++)
			if (i == 0 && j == 0)
				g[i][j] = 0;
			else
			{
				g[i][j] = x % 3;
				x /= 3;
			}
	memset(flag, 0, sizeof(flag));
	dfs(0, 0);
}
void init()
{
	int i, j, tot, num, k, next_i, next_j;
	base[0] = 1;
	for (i = 1; i < N; i++)
		base[i] = base[i - 1] * 3;
	memset(tag, 0, sizeof(tag));
	for (i = 0; i < exp(N); i++)
	{
		one[i] = 0;
		for (j = 0; j < N; j++)
			if (i & exp(j))
				one[i]++;
	}
	tag[0][0] = 1;
	for (i = 1; i < M; i++)
	{
		get_g(i);
		tot = num = 0;
		for (j = 0; j < 3; j++)
			for (k = 0; k < 3; k++)
				if (g[j][k])
				{
					tot++;
					if (g[j][k] == 2)
						num++;
				}
		for (j = 0; j < exp(tot); j++)
			if (one[j] == num)
			{
				for (k = 0; !tag[i][j] && k < 3; k++)
					for (int kk = 0; !tag[i][j] && kk < 3; kk++)
						if (g[k][kk] == (j % 2 + 1) && flag[k][kk])
						{
							next_i = i - base[k * 3 + kk - 1] * g[k][kk];
							next_j = j / 2;
							if (tag[next_i][next_j])
								tag[i][j] = 1;

						}

			}
	}
	cnt[0] = 0;
	for (i = 0; i < M; i++)
	{
		cnt[i] = 0;
		for (j = 0; j < exp(N); j++)
			if (tag[i][j])
				cnt[i]++;
	}
}
int main()
{
	int cas, i, j, st, k;
	char tmp[3][10];
	init();
	cas = 0;
	while (scanf("%s", tmp[0]) != EOF)
	{
		cas++;
		scanf("%s", tmp[1]);
		scanf("%s", tmp[2]);
		/*
		 for(i=0;i<3;i++)
		 puts(tmp[i]);
		 */
		st = 0;
		k = 0;
		for (i = 0; i < 3; i++)
			for (j = 0; j < 3; j++)
				if (i == 0 && j == 0)
					continue;
				else if (tmp[i][j] == 'B')
					st += base[k++];
				else if (tmp[i][j] == 'G')
					st += base[k++] * 2;
				else
					k++;
		//cout<<st<<endl;
		printf("Case %d: %d\n", cas, cnt[st]);
	}
	return 0;
}
